package com.xigege.netty.httpExample;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
@SuppressWarnings("all")
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {
    //初始化管道，向管道加入处理器
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //得到管道
        ChannelPipeline pipeline = ch.pipeline();

        //加入netty提供的httpServerCodec（Codec指：code和decoder）编解码器
        //加入处理器的时候也可以给它取名字
        /**
         * HttpServerCodec说明
         * 1. HttpServerCodec是netty提供的处理http的编解码器，并且实现了 HttpServerUpgradeHandler.SourceCodec
         */
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());

        //增加一个自定义的handler
        pipeline.addLast("MyTestHttpServerHandle",new TestHttpServerHandle());

    }
}
